package com.jsu.clubmanagementsystem.service.activity.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jsu.clubmanagementsystem.common.ErrorCode;
import com.jsu.clubmanagementsystem.exception.BusinessException;
import com.jsu.clubmanagementsystem.model.entity.ActivityMembership;
import com.jsu.clubmanagementsystem.mapper.ActivityMembershipMapper;
import com.jsu.clubmanagementsystem.service.activity.ActivityMembershipService;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;

/**
* @author 24753
* @description 针对表【activity_membership(社团活动人员关系)】的数据库操作Service实现
* @createDate 2025-05-13 17:19:16
*/
@Service
public class ActivityMembershipServiceImpl extends ServiceImpl<ActivityMembershipMapper, ActivityMembership>
    implements ActivityMembershipService {

    /**
     * 获取查询封装
     *
     * @param userId
     * @param activityId
     * @return
     */
    @Override
    public QueryWrapper<ActivityMembership> getQueryWrapper(Long userId, Long activityId) {
        if (userId == null && activityId == null) {
            throw new BusinessException(ErrorCode.PARAM_ERROR, "查询参数为空");
        }
        QueryWrapper<ActivityMembership> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(ObjectUtils.isNotEmpty(userId) && userId > 0, "userId", userId);
        queryWrapper.eq(ObjectUtils.isNotEmpty(activityId) && activityId > 0, "activityId", activityId);
        return queryWrapper;
    }

    @Override
    public boolean isUserInActivity(Long userId, Long activityId) {
        if (userId == null && activityId == null) {
            throw new BusinessException(ErrorCode.PARAM_ERROR, "查询参数为空");
        }
        QueryWrapper<ActivityMembership> queryWrapper = getQueryWrapper(userId, activityId);
        return this.count(queryWrapper) > 0;
    }
}




